#!/bin/bash
export CPUS=`grep -c processor /proc/cpuinfo`
export ARCH=arm
export CROSS_COMPILE=/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

if [ ! -d "output" ]; then
    mkdir output
fi

do_build_debug()
{
	if [ $# -lt 1 ]; then
		echo "input few args ..."
		exit
	fi
	case $1 in
		-b)
			make  O=output vexpress_ca9x4_defconfig
			make  O=output -j${CPUS}
		;;
		-c)
			make -C output clean
		;;
		-r)
			qemu-system-arm -M vexpress-a9 -m 512M \
			-kernel output/u-boot \
			-nographic
		;;
		-d)
			qemu-system-arm -M vexpress-a9 -m 512M \
			-kernel output/u-boot \
			-nographic \
			-S -s
		;;
		*)
			;;
	esac
}

do_build_debug $1
